package com.ljx.rag.rag.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ljx.rag.rag.domain.dto.OllamaMessage;
import com.ljx.rag.rag.domain.entity.FileVector;
import com.ljx.rag.rag.domain.vo.req.ChatReq;
import com.ljx.rag.rag.domain.vo.req.ChatWithFileReq;
import com.ljx.rag.rag.mapper.FileVectorMapper;
import com.ljx.rag.rag.service.AiService;
import com.ljx.rag.rag.service.ChatService;
import com.ljx.rag.rag.service.EmbeddingService;
import com.ljx.rag.rag.util.FileContentExtractor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;


@Service
public class ChatServiceImpl implements ChatService {

    @Autowired
    private AiService aiService;

    @Autowired
    private FileContentExtractor fileContentExtractor;

    @Autowired
    private FileVectorMapper fileVectorMapper;

    @Autowired
    private EmbeddingService embeddingService;

    @Override
    public Flux<String> chat(ChatReq req) {
        return aiService.callChatApi(req.getMessages());
    }

    @Override
    public Flux<String> chatWithFile(ChatWithFileReq req) {
        List<FileVector> fileVectors = fileVectorMapper.selectList(new LambdaQueryWrapper<>());
        FileVector fileVector = fileVectors.get(0);
//
        String msg = "你现在是我的专属AI机器小助手，请根据下面的内容：" + fileVector.getContent() + "，回答这个问题" + req.getMsg();
        return aiService.callChatApi(Arrays.asList(new OllamaMessage("user", msg)));
    }
}
